import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;

public class Testclass {

 public static void main(String argv[]) {

  try {
  File file = new File("liv.xml");
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  Document doc = db.parse(file);
  doc.getDocumentElement().normalize();
  System.out.println("Root element " + doc.getDocumentElement().getNodeName());
  doSomething(doc.getDocumentElement());


  } catch (Exception e) {
    e.printStackTrace();
  }
 }
 public static void doSomething(Node node){
        NodeList nodeLst = node.getChildNodes();
        for (int i = 0; i < nodeLst.getLength(); i++) {
        Node currentNode = nodeLst.item(i);
        if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
            System.out.println(currentNode.getNodeName());
            Attr attr = (Attr)currentNode.getAttributes().item(0);
            System.out.println(attr.getValue());
        } else if ( currentNode.getNodeType() == Node.TEXT_NODE) {
            System.out.println(currentNode.getTextContent());
        }
            doSomething(currentNode);
}
        }
 }
 
